{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Classification skill with Chain-of-Thoughts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>text</th>\n",
       "      <th>category</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Apple product with a sleek design.</td>\n",
       "      <td>Electronics</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Laptop stand for the kitchen.</td>\n",
       "      <td>Furniture/Home Decor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Chocolate leather boots.</td>\n",
       "      <td>Footwear/Clothing</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Wooden cream for surfaces.</td>\n",
       "      <td>Furniture/Home Decor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Natural finish for your lips.</td>\n",
       "      <td>Beauty/Personal Care</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 text              category\n",
       "0  Apple product with a sleek design.           Electronics\n",
       "1       Laptop stand for the kitchen.  Furniture/Home Decor\n",
       "2            Chocolate leather boots.     Footwear/Clothing\n",
       "3          Wooden cream for surfaces.  Furniture/Home Decor\n",
       "4       Natural finish for your lips.  Beauty/Personal Care"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "df = pd.DataFrame([\n",
    "    {\"text\": \"Apple product with a sleek design.\", \"category\": \"Electronics\"},\n",
    "    {\"text\": \"Laptop stand for the kitchen.\", \"category\": \"Furniture/Home Decor\"},\n",
    "    {\"text\": \"Chocolate leather boots.\", \"category\": \"Footwear/Clothing\"},\n",
    "    {\"text\": \"Wooden cream for surfaces.\", \"category\": \"Furniture/Home Decor\"},\n",
    "    {\"text\": \"Natural finish for your lips.\", \"category\": \"Beauty/Personal Care\"}\n",
    "])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Applying skill: product_category_classification\n",
       "</pre>\n"
      ],
      "text/plain": [
       "Applying skill: product_category_classification\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█| 5/5 [00:09<00:00, \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>text</th>\n",
       "      <th>category</th>\n",
       "      <th>thoughts</th>\n",
       "      <th>predicted_class</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Apple product with a sleek design.</td>\n",
       "      <td>Electronics</td>\n",
       "      <td>Electronics/Technology, Home Goods/Furniture</td>\n",
       "      <td>Electronics</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Laptop stand for the kitchen.</td>\n",
       "      <td>Furniture/Home Decor</td>\n",
       "      <td>1. Kitchen Accessories\\n2. Home Organization\\n...</td>\n",
       "      <td>Furniture/Home Decor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Chocolate leather boots.</td>\n",
       "      <td>Footwear/Clothing</td>\n",
       "      <td>1. Footwear: This text clearly mentions boots,...</td>\n",
       "      <td>Footwear/Clothing</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Wooden cream for surfaces.</td>\n",
       "      <td>Furniture/Home Decor</td>\n",
       "      <td>1. Home and Kitchen: This category would inclu...</td>\n",
       "      <td>Furniture/Home Decor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Natural finish for your lips.</td>\n",
       "      <td>Beauty/Personal Care</td>\n",
       "      <td>1. Beauty &amp; Personal Care: Lip Care\\n2. Cosmet...</td>\n",
       "      <td>Beauty/Personal Care</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 text              category  \\\n",
       "0  Apple product with a sleek design.           Electronics   \n",
       "1       Laptop stand for the kitchen.  Furniture/Home Decor   \n",
       "2            Chocolate leather boots.     Footwear/Clothing   \n",
       "3          Wooden cream for surfaces.  Furniture/Home Decor   \n",
       "4       Natural finish for your lips.  Beauty/Personal Care   \n",
       "\n",
       "                                            thoughts       predicted_class  \n",
       "0       Electronics/Technology, Home Goods/Furniture           Electronics  \n",
       "1  1. Kitchen Accessories\\n2. Home Organization\\n...  Furniture/Home Decor  \n",
       "2  1. Footwear: This text clearly mentions boots,...     Footwear/Clothing  \n",
       "3  1. Home and Kitchen: This category would inclu...  Furniture/Home Decor  \n",
       "4  1. Beauty & Personal Care: Lip Care\\n2. Cosmet...  Beauty/Personal Care  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from adala.agents import Agent\n",
    "from adala.skills import ClassificationSkill\n",
    "\n",
    "agent = Agent(\n",
    "    skills=ClassificationSkill(\n",
    "        name='product_category_classification',\n",
    "        instructions='Categorize text into different product categories.',\n",
    "        input_template='Text: {text}',\n",
    "        output_template='Thoughts: {thoughts}\\n\\nClassification: {predicted_class}',\n",
    "        labels={'predicted_class': [\n",
    "            \"Footwear/Clothing\",\n",
    "            \"Electronics\",\n",
    "            \"Food/Beverages\",\n",
    "            \"Furniture/Home Decor\",\n",
    "            \"Beauty/Personal Care\"\n",
    "        ]},\n",
    "    )\n",
    ")\n",
    "\n",
    "agent.run(df)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "adala",
   "language": "python",
   "name": "adala"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
